<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();

if($_RQ['op']=='main'){
		
	$id = intval($_RQ['id']);
		if (empty($id)) 
		{
			
			$member = getMember($_SESSION['uid']);
		}
		else 
		{
			$member = getMember($id);
		}
		if (empty($member)) 
		{
			exi('未找到用户!', 'error', '/index/');
		}
		$condition = ' p.uniacid=:uniacid and p.mid=:mid and p.pid>0 and p.deleted=0 and p.checked=1';
		$params = array(':uniacid' => $_SESSION['uniacid'], ':mid' => $member['mid']);
		$sql = 'select p.id, p.content, p.views,' . "\n" . '                  parent.id as parentid, parent.nickname as parentnickname,parent.title as parenttitle ,parent.images as parentimages,' . "\n" . '                  rparent.nickname as rparentnickname,' . "\n" . '                  b.title as boardtitle, b.logo as boardlogo,b.id as boardid' . "\n" . '                  from ' . tablename('jy_sns_post') . ' p ' . ' left join ' . tablename('jy_sns_post') . ' parent on p.pid = parent.id ' . ' left join ' . tablename('jy_sns_post') . ' rparent on p.rpid = rparent.id ' . ' left join ' . tablename('jy_sns_board') . ' b on b.id=p.bid ' . '   where 1 and ' . $condition . ' order by p.createtime desc';
		$list = pdo_fetchall($sql, $params);
		//$total = pdo_fetchcolumn('select count(*) from ' . tablename('ewei_shop_sns_post') . ' p ' . ' left join ' . tablename('ewei_shop_sns_post') . ' parent on p.pid = parent.id ' . ' left join ' . tablename('ewei_shop_sns_post') . ' rparent on p.rpid = rparent.id ' . ' where 1 and ' . $condition, $params);
		foreach ($list as &$r ) 
		{
			$parentnickname = $r['rparentnickname'];
			if (empty($parentnickname)) 
			{
				$parentnickname = $r['parentnickname'];
			}
			$r['parentnickname'] = $parentnickname;
			$r['boardlogo'] = tomedia($r['boardlogo']);
			$images = unserialize($r['parentimages']);
			$thumb = '';
			if (is_array($images) && !(empty($images))) 
			{
				$thumb = $images[0];
			}
			if (empty($thumb)) 
			{
				$thumb = $r['boardlogo'];
			}
			$r['image'] = tomedia($thumb);
		}
		$return['mid'] = $member['mid'];
		$return['mymid'] = $_SESSION['uid'];
		$return['member'] = $member;
		exi($return);
	}
?>